package com.sgy.handwrite_ioc_aop.service.impl;

import com.sgy.handwrite_ioc_aop.dao.AccountDao;
import com.sgy.handwrite_ioc_aop.dao.impl.JdbcAccountDaoImpl;
import com.sgy.handwrite_ioc_aop.factory.BeanFactory;
import com.sgy.handwrite_ioc_aop.pojo.Account;
import com.sgy.handwrite_ioc_aop.service.TransferService;
import com.sgy.handwrite_ioc_aop.utils.ConnectionUtils;
import com.sgy.handwrite_ioc_aop.utils.TransactionManager;

import java.sql.Connection;

/**
 * @author Administrator
 * @date 2025/7/13 11:58
 * @description
 */
public class TransferServiceImpl implements TransferService {

//    private AccountDao accountDao = new JdbcAccountDaoImpl();
//    private AccountDao accountDao = (AccountDao) BeanFactory.getBean("accountDao");

    private AccountDao accountDao;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney()-money);
        to.setMoney(to.getMoney()+money);

        accountDao.updateAccountByCardNo(to);
        accountDao.updateAccountByCardNo(from);
    }
}
